﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;
using System.IO;

namespace MyTestProject {
    public class TestSampleSpline {

        /**
         * Spline補間、Constantリピートのテスト
         * */
        [Fact]
        public void TestSplineConstant () {
            var kseq = new KeyframeSequence (4, 1, KeyframeSequence.Spline);
            kseq.RepeatMode = KeyframeSequence.Constant;
            kseq.Duration = 5;

            kseq.SetKeyframe (0, 1, new float[] { 2.0f });
            kseq.SetKeyframe (1, 2, new float[] { 4.0f });
            kseq.SetKeyframe (2, 3, new float[] { 4.0f });
            kseq.SetKeyframe (3, 4, new float[] { 2.0f });

            // 目視で確認する
            using (StreamWriter writer = new StreamWriter ("TestSampleSpline-001.txt")) {
                for (var i = 0; i < 100; i++) {
                    var x = i / 100.0f * 10;
                    var y = kseq.Sample (x, 0);
                    writer.WriteLine ("" + x.ToString("#0.00") + " , " + y.ToString("#0.00"));
                }
            }
        }

        /**
         * Spline補間、Loopリピートのテスト
         * */
        [Fact]
        public void TestSplineLoop () {
            var kseq = new KeyframeSequence (4, 1, KeyframeSequence.Spline);
            kseq.RepeatMode = KeyframeSequence.Loop;
            kseq.Duration = 5;

            kseq.SetKeyframe (0, 1, new float[] { 2.0f });
            kseq.SetKeyframe (1, 2, new float[] { 4.0f });
            kseq.SetKeyframe (2, 3, new float[] { 4.0f });
            kseq.SetKeyframe (3, 4, new float[] { 2.0f });

            // 目視で確認する
            using (StreamWriter writer = new StreamWriter ("TestSampleSpline-002.txt")) {
                for (var i = 0; i < 100; i++) {
                    var x = i / 100.0f * 10;
                    var y = kseq.Sample (x, 0);
                    writer.WriteLine ("" + x.ToString ("#0.00") + " , " + y.ToString ("#0.00"));
                }
            }
        }
    }
}
